/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2019 HUST Dian Group
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Original Author: Pengyu Liu <eicliupengyu@gmail.com>
 */
#pragma once
#include <map>
#include "ns3/timer.h"
#include "ns3/random-variable-stream.h"
#include "robo-common.h"
#include "robo-actor.h"
#include "robo-weapon.h"
#include "robo-supply.h"

namespace ns3 {
class RoboSupply;
class RoboJudge;
class RoboBase : public RoboActor
{
  friend class RoboTeamHelper;
  friend class RoboJudge;
  friend class RoboAmmo;
  friend class RoboSupply;

public:
  RoboBase ();
  virtual ~RoboBase ();
  static TypeId GetTypeId (void);
  virtual TypeId GetInstanceTypeId (void) const;

  typedef Callback<void, uint8_t, FVector> IndicateLocationCallback;

  uint8_t GetUid (void) const;
  uint8_t GetTeam (void) const;
  RoboType GetRoboType (void) const;
  std::string GetName (void) const;
  int GetLife (void) const;
  int GetLevel (void) const;
  int GetExp (void) const;
  int GetHeat (AmmoType ammoType) const;
  int GetMaxHeat (AmmoType ammoType) const;
  bool ShootAmmo (FVector speed, AmmoType ammoType);
  bool GiveAmmoTo (uint8_t targetId, int num, AmmoType ammoType);
  int GetAmmoNum (AmmoType ammoType) const;
  bool UpgradeLifeLevel (void);
  bool UpgradeMaxAmmoSpeed (void);
  void Resurrection (uint8_t target);

  uint32_t AddIndicateLocationCallback (IndicateLocationCallback cb);

protected:
  bool m_invincible{false};
  uint8_t m_uid{255};
  uint8_t m_team{255};
  RoboType m_roboType{RoboTypeHero};
  std::string m_name;
  float m_life{0.f};
  int m_virtualShield{0};
  int m_maxLifeLevel{0};
  int m_maxAmmoSpeedLevel{0};
  int m_level{0};
  float m_exp{0.f};
  RoboWeapon m_weapon[MAX_WEAPON_ID];
  Ptr<UniformRandomVariable> m_random;
  Timer m_heatTimer;
  Timer m_expIncTimer;
  Timer m_virtualShieldTimer;
  Time m_roboCollisionInterval;
  Time m_lastRoboCollision;
  Time m_nextLifeInc;
  std::vector<IndicateLocationCallback> m_locationCallbackList;

  void HandleCollision (Ptr<RoboActor> oth);
  void HandleHeat ();
  void HandleExpAutoInc ();
  void HandleVirtualShield ();
  void UpdateStatus ();
  void IndicateLocation (Ptr<RoboBase> oth);
  void DoResurrection ();
  void CancelInvincible ();
  void InitPlot (FILE *fp);
  void PlotSelf (FILE *fp);

private:
  static uint8_t m_uidNum;
};
} // namespace ns3